package com.cosina.game.robodefence.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class CanvasUtil {
	
	public static final int LEFT = 0;
	public static final int CENTER = 1;
	public static final int RIGHT = 2;
	
	public static void drawText(Canvas canvas, Object content, int locationX, int locationY, Paint paint ,int textSize, int location){
		paint.setTextSize(textSize);

		String contentStr = content.toString();
		if(location == CENTER){
			float width = paint.measureText(contentStr);
			locationX -= width/2;
		}else if(location == RIGHT){
			float width = paint.measureText(contentStr);
			locationX -= width;
		}
		
		canvas.drawText(contentStr, locationX, locationY, paint);
	}
	
	public static void drawAlphaBitmap(Canvas canvas, Bitmap bitmap, int x, int y,
			Paint paint, int alpha) {
		int alphaBack = paint.getAlpha();
		paint.setAlpha(alpha);
		canvas.drawBitmap(bitmap, x, y, paint);
		paint.setAlpha(alphaBack);
	}
}
